package com.ibm.law.ui.system.setup;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.ibm.law.data.CachedData;
import com.ibm.law.domain.Institute;
import com.ibm.law.service.system.InstituteService;
import com.ibm.law.ui.AppWindow;

public class InstituteSetup extends Composite {
	private DataBindingContext m_bindingContext;
	private Text lisenceNo;
	private Text text;
	private Text text_1;
	private Text text_2;
	private Text text_3;
	private Text text_4;
	private Text text_5;
	private Text text_6;
	private Text text_7;
	private Text text_8;
	private Text text_9;
	private Text text_10;
	private Text text_11;
	private Text text_12;
	private Text text_13;
	private Text text_14;
	private Institute institute=CachedData.INSTITUTE;
	private Label lblName;
	public Institute getInstitute() {
		return institute;
	}

	public void setInstitute(Institute institute) {
		this.institute = institute;
	}

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public InstituteSetup(Composite parent, int style) {
		super(parent, style);
		setLayout(new GridLayout(4, false));
		
		Label lblNewLabel = new Label(this, SWT.NONE);
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel.setText("机构名称");
		
		lblName = new Label(this, SWT.NONE);
		
		Label lblNewLabel_2 = new Label(this, SWT.NONE);
		lblNewLabel_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_2.setText("许可证证号");
		
		lisenceNo = new Text(this, SWT.BORDER);
		lisenceNo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_1 = new Label(this, SWT.NONE);
		lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_1.setText("法定代表人");
		
		text = new Text(this, SWT.BORDER);
		text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_3 = new Label(this, SWT.NONE);
		lblNewLabel_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_3.setText("机构负责人");
		
		text_1 = new Text(this, SWT.BORDER);
		text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_4 = new Label(this, SWT.NONE);
		lblNewLabel_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_4.setText("鉴定业务范围");
		
		text_2 = new Text(this, SWT.BORDER);
		text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
		
		Label lblNewLabel_5 = new Label(this, SWT.NONE);
		lblNewLabel_5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_5.setText("有效期限");
		
		text_3 = new Text(this, SWT.BORDER);
		text_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_6 = new Label(this, SWT.NONE);
		lblNewLabel_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_6.setText("颁证机关");
		
		text_4 = new Text(this, SWT.BORDER);
		text_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_7 = new Label(this, SWT.NONE);
		lblNewLabel_7.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_7.setText("机构住所");
		
		text_5 = new Text(this, SWT.BORDER);
		text_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
		
		Label lblNewLabel_8 = new Label(this, SWT.NONE);
		lblNewLabel_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_8.setText("邮编");
		
		text_6 = new Text(this, SWT.BORDER);
		text_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_9 = new Label(this, SWT.NONE);
		lblNewLabel_9.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_9.setText("电话");
		
		text_7 = new Text(this, SWT.BORDER);
		text_7.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_10 = new Label(this, SWT.NONE);
		lblNewLabel_10.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_10.setText("传真");
		
		text_8 = new Text(this, SWT.BORDER);
		text_8.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_11 = new Label(this, SWT.NONE);
		lblNewLabel_11.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_11.setText("手机");
		
		text_9 = new Text(this, SWT.BORDER);
		text_9.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_12 = new Label(this, SWT.NONE);
		lblNewLabel_12.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_12.setText("Email");
		
		text_10 = new Text(this, SWT.BORDER);
		text_10.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
		
		Label lblNewLabel_13 = new Label(this, SWT.NONE);
		lblNewLabel_13.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_13.setText("网址");
		
		text_11 = new Text(this, SWT.BORDER);
		text_11.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
		
		Label lblNewLabel_14 = new Label(this, SWT.NONE);
		lblNewLabel_14.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_14.setText("账号");
		
		text_12 = new Text(this, SWT.BORDER);
		text_12.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_15 = new Label(this, SWT.NONE);
		lblNewLabel_15.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_15.setText("户名");
		
		text_13 = new Text(this, SWT.BORDER);
		text_13.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label lblNewLabel_16 = new Label(this, SWT.NONE);
		lblNewLabel_16.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_16.setText("开户行");
		
		text_14 = new Text(this, SWT.BORDER);
		GridData gd_text_14 = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		gd_text_14.widthHint = 211;
		text_14.setLayoutData(gd_text_14);
		
		Button btnNewButton = new Button(this, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				LisenceImageDialog dialog=new LisenceImageDialog(AppWindow
						.getInstance().getShell(), SWT.DIALOG_TRIM
						| SWT.APPLICATION_MODAL);
				dialog.open();
			}
		});
		GridData gd_btnNewButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_btnNewButton.widthHint = 66;
		btnNewButton.setLayoutData(gd_btnNewButton);
		btnNewButton.setText("许可证");
		
		Label label = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
		GridData gd_label = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
		gd_label.widthHint = 444;
		label.setLayoutData(gd_label);
		new Label(this, SWT.NONE);
		new Label(this, SWT.NONE);
		
		Button btnNewButton_1 = new Button(this, SWT.NONE);
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				InstituteService instituteService=new InstituteService();
				instituteService.update(institute);
			}
		});
		btnNewButton_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		btnNewButton_1.setText("保存");
		
		Button btnNewButton_2 = new Button(this, SWT.NONE);
		btnNewButton_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				 if (e.getSource() instanceof Button) {
					Button button = (Button) e.getSource();
					button.getShell().close();
					
				}
			}
		});
		GridData gd_btnNewButton_2 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_btnNewButton_2.widthHint = 58;
		btnNewButton_2.setLayoutData(gd_btnNewButton_2);
		btnNewButton_2.setText("退出");
		m_bindingContext = initDataBindings();

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeTextLblNameObserveWidget = WidgetProperties.text().observe(lblName);
		IObservableValue nameInstituteObserveValue = BeanProperties.value("name").observe(institute);
		bindingContext.bindValue(observeTextLblNameObserveWidget, nameInstituteObserveValue, null, null);
		//
		IObservableValue observeTextLisenceNoObserveWidget = WidgetProperties.text(SWT.Modify).observe(lisenceNo);
		IObservableValue lisenceNoInstituteObserveValue = BeanProperties.value("lisenceNo").observe(institute);
		bindingContext.bindValue(observeTextLisenceNoObserveWidget, lisenceNoInstituteObserveValue, null, null);
		//
		IObservableValue observeTextTextObserveWidget = WidgetProperties.text(SWT.Modify).observe(text);
		IObservableValue representativeInstituteObserveValue = BeanProperties.value("representative").observe(institute);
		bindingContext.bindValue(observeTextTextObserveWidget, representativeInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_1ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_1);
		IObservableValue personInChargeInstituteObserveValue = BeanProperties.value("personInCharge").observe(institute);
		bindingContext.bindValue(observeTextText_1ObserveWidget, personInChargeInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_2ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_2);
		IObservableValue businessScopeInstituteObserveValue = BeanProperties.value("businessScope").observe(institute);
		bindingContext.bindValue(observeTextText_2ObserveWidget, businessScopeInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_14ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_14);
		IObservableValue accountBankInstituteObserveValue = BeanProperties.value("accountBank").observe(institute);
		bindingContext.bindValue(observeTextText_14ObserveWidget, accountBankInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_13ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_13);
		IObservableValue accountNameInstituteObserveValue = BeanProperties.value("accountName").observe(institute);
		bindingContext.bindValue(observeTextText_13ObserveWidget, accountNameInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_12ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_12);
		IObservableValue accountNoInstituteObserveValue = BeanProperties.value("accountNo").observe(institute);
		bindingContext.bindValue(observeTextText_12ObserveWidget, accountNoInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_11ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_11);
		IObservableValue websiteInstituteObserveValue = BeanProperties.value("website").observe(institute);
		bindingContext.bindValue(observeTextText_11ObserveWidget, websiteInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_10ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_10);
		IObservableValue emailInstituteObserveValue = BeanProperties.value("email").observe(institute);
		bindingContext.bindValue(observeTextText_10ObserveWidget, emailInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_9ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_9);
		IObservableValue cellphoneInstituteObserveValue = BeanProperties.value("cellphone").observe(institute);
		bindingContext.bindValue(observeTextText_9ObserveWidget, cellphoneInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_8ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_8);
		IObservableValue faxInstituteObserveValue = BeanProperties.value("fax").observe(institute);
		bindingContext.bindValue(observeTextText_8ObserveWidget, faxInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_7ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_7);
		IObservableValue telInstituteObserveValue = BeanProperties.value("tel").observe(institute);
		bindingContext.bindValue(observeTextText_7ObserveWidget, telInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_6ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_6);
		IObservableValue zipcodeInstituteObserveValue = BeanProperties.value("zipcode").observe(institute);
		bindingContext.bindValue(observeTextText_6ObserveWidget, zipcodeInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_5ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_5);
		IObservableValue addressInstituteObserveValue = BeanProperties.value("address").observe(institute);
		bindingContext.bindValue(observeTextText_5ObserveWidget, addressInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_4ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_4);
		IObservableValue authorityInstituteObserveValue = BeanProperties.value("authority").observe(institute);
		bindingContext.bindValue(observeTextText_4ObserveWidget, authorityInstituteObserveValue, null, null);
		//
		IObservableValue observeTextText_3ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_3);
		IObservableValue expireDateInstituteObserveValue = BeanProperties.value("expireDate").observe(institute);
		bindingContext.bindValue(observeTextText_3ObserveWidget, expireDateInstituteObserveValue, null, null);
		//
		return bindingContext;
	}
}
